package com.zbkj.admin.handler;

import org.apache.ibatis.type.LocalDateTimeTypeHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;

/**
 * javaType=LocalDateTime.class, jdbcType=JdbcType.DATE, typeHandler=TimestampToLocalDateTimeTypeHandler.class
 */
public class TimestampToLocalDateTimeTypeHandler extends LocalDateTimeTypeHandler {
    @Override
    public LocalDateTime getResult(ResultSet rs, String columnName) throws SQLException {
        Object object = rs.getObject(columnName);
        if (object instanceof Timestamp) {
            return LocalDateTime.ofInstant(((Timestamp) object).toInstant(), ZoneId.of("Asia/Shanghai"));
        }
        return super.getResult(rs, columnName);
    }
}